<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class GetUserToken extends Command {
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'getUserToken
                                        {uid : 用户id}
                                        {--m|model= : 模型名称}
                                        {--p|path= : 模型路径}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '生成用户token
                                使用方法1:  php artisan getUserToken 1 -m Admin   自动调用 Modules\Admin\Entities\Admin模型
                                使用方法  php artisan getUserToken 1 -m Admin -p App  调用  App\Admin 模型
                            ';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle() {
        $uid = $this->argument('uid');
        $model = $this->option('model');
        $path = $this->option('path');
        if (isset($path) && strlen($path)) {
            $model = $path . '\\' . $model;
        } else {
            $model = "Modules\\$model\Entities\\$model";
        }
        $user = $model::find($uid);
        if (!$user) {
            dd('数据不存在');
        }
        $token = $user->createToken('user')->accessToken;
        dd($token);
    }
}
